function Bytes2Str(arr)

{

    var str = "";

    for(var i=0; i<arr.length; i++)

    {

       var tmp = arr[i].toString(16);
       console.log("tmp"+tmp)

       if(tmp.length == 1)

       {

           tmp = "0" + tmp;

       }

       str += tmp;

    }

    return str;

}

function Str2Bytes(str)

{

var pos = 0;

var len = str.length;

if(len %2 != 0)

{

return null;

}

len /= 2;

var hexA = new Array();

for(var i=0; i<len; i++)

{

var s = str.substr(pos, 2);

var v = parseInt(s, 16);

hexA.push(v);

pos += 2;

}

return hexA;


}



const Bytes2HexString = (b)=> {
    let hexs = "";
    for (let i = 0; i < b.length; i++) {
      let hex = (b[i]).toString(16);
      if (hex.length === 1) {
        hexs = '0' + hex;
      }
      hexs += hex.toUpperCase();
    }
    return hexs;
  }


  
function sumCheck( b, len){
    var sum = 0;
    for(var i = 0; i < len; i++){
        sum = sum + b[i];
    }
    if(sum > 0xff){ //超过了255，使用补码（补码 = 原码取反 + 1）
        sum = ~sum;
        sum = sum + 1;
    }
    return (sum & 0xff);
}


function number2Bytes(i) {
    var arr = new Int8Array(1);
    arr[0] = 0;
    var buf = Buffer.from(arr.buffer, 'hex');
    buf.writeUInt8(i);
     
    console.log("buf:", buf);
    console.log("buffer length :", buf.length); 
    var iNumber = buf.readInt8();
    console.log("iNumber:", iNumber);
    return buf;
    };

  var num="A016018200000000010206313139313130303130313031";
 var a=Str2Bytes(num);

 var c=sumCheck(a,23);
 var d=number2Bytes(c);
  console.log("a"+a);

  var b=Bytes2Str(d)
  console.log("b"+b);